#include "extractorConcatenateVector.h"
#include "extractorLabColorVector.h"
#include "extractorMultiScaleDenseSiftVector.h"
#include "extractorLocationVector.h"
#include "extractorShapeVector.h"
#include "extractorBoundaryCenterVector.h"
#include "extractorVolumneVector.h"
#include "configurationParameters.h"
#include "grabcut.h"

extractorConcatenateVector::extractorConcatenateVector(cv::Mat src_img, char* _labelImage, Slic _clustering, Mat siftDictionary, Mat colorDictionary) {
	extractorLabColorVector extractorLabColorVector(src_img, _labelImage, _clustering, colorDictionary);
	extractorMultiScaleDenseSiftVector extractorMultiScaleDenseSiftVector(src_img, _labelImage, _clustering, siftDictionary);
	extractorLocationVector extractorLocationVector(_labelImage, _clustering);
	IplImage *tmp = cvLoadImage(_labelImage);
	extractorShapeVector extractorShapeVector(tmp, _labelImage, _clustering);
	extractorBoundaryCenterVector extractorBoundaryCenterVector(_labelImage, _clustering);
	extractorVolumneVector extractorVolumneVector(_labelImage, _clustering);
	
	Grabcut grabcut;
	grabcut.segment(src_img, configurationParameters::gcRatioCenter());
	cv::Mat grabcutMask = grabcut.loadMask();
	vector<int> label_fg = _clustering.assign_label_fg(grabcutMask);

	for (int i = 0; i < _clustering.getCenter_counts().size(); ++i) {
		concatenateVector concatenateVector(configurationParameters::sizeSuperpixelDescriptor(), i, _labelImage);

		colorVector colorVector = extractorLabColorVector.getListVector().at(i);
		multiScaleDenseSiftVector multiScaleDenseSiftVector = extractorMultiScaleDenseSiftVector.getListVector().at(i);
		locationVector locationVector = extractorLocationVector.getListVector().at(i);
		shapeVector shapeVector = extractorShapeVector.getListVector().at(i);
		boundaryCenterVector boundaryCenterVector = extractorBoundaryCenterVector.getListVector().at(i);
		volumneVector volumneVector = extractorVolumneVector.getListVector().at(i);
		// create 1076-dim vector
		concatenateVector.appendVector(colorVector.getVectorValue());
		concatenateVector.appendVector(multiScaleDenseSiftVector.getVectorValue());
		concatenateVector.appendVector(locationVector.getVectorValue());
		concatenateVector.appendVector(shapeVector.getVectorValue());
		concatenateVector.appendVector(boundaryCenterVector.getVectorValue());
		concatenateVector.appendVector(volumneVector.getVectorValue());
		concatenateVector.setLabelForegroundBackground(label_fg.at(i));
		listVector.push_back(concatenateVector);
	}
}

vector<concatenateVector> extractorConcatenateVector::getListVector() {
	return listVector;
}